define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ddns/domain/index' + location.search,
                    add_url: 'ddns/domain/add',
                    edit_url: 'ddns/domain/edit',
                    del_url: 'ddns/domain/del',
                    multi_url: 'ddns/domain/multi',
                    table: 'ddns_domain',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'domain_name', title: __('Domain_name')},
                        {field: 'main_domain', title: __('Main_domain')},
                        {field: 'last_ip', title: __('Last_ip')},
                        {field: 'record_id', title: __('Record_id')},
                        {field: 'access_ip', title: __('Access_ip')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('操作'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    text: __(''),
                                    title: __('编辑'),
                                    classname: 'btn btn-xs btn-success btn-dialog btn-check',
                                    icon: 'fa fa-pencil',
                                    url: 'ddns/domain/edit',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        //console.log(row);
                                        return true;

                                    },

                                },

                            ],
                            formatter: Table.api.formatter.buttons,operate:false
                        }
                        ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
